package com.xyyl.patient.service.continuationonline;

import java.util.Date;

import org.apache.commons.lang.math.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xyyl.patient.core.util.DateUtils;
import com.xyyl.patient.entity.continuationonline.ContinuationOnline;
import com.xyyl.patient.mapper.continuationonline.ContinuationOnlineMapper;

/**
 * @ClassName: ContinuationOnlineServiceImpl
 * @Description: 患者信息Service
 * @author tangwei
 * @date 2018年3月5日
 *
 */
@Service("continuationOnlineService")
public class ContinuationOnlineServiceImpl implements ContinuationOnlineService {

	@Autowired
	private ContinuationOnlineMapper continuationOnlineMapper;

	@Override
	public Integer insertContinuationOnline(ContinuationOnline continuationOnline) {
		String preCode = DateUtils.formatDatetime(new Date(), "yyyyMMddHHss") + RandomUtils.nextInt(99999);
		continuationOnline.setOrdersn("CO-" + preCode);
		continuationOnline.setStatus(1);
		continuationOnlineMapper.insert(continuationOnline);
		return continuationOnline.getId();
	}

	@Override
	public boolean checkUserOrder(ContinuationOnline continuationOnline) {
		Integer res = continuationOnlineMapper.checkUserOrder(continuationOnline);
		if (res > 0) {
			return false;
		} else {
			return true;
		}
	}

}
